import net.sf.emu.cs.ConnectTheard;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;


public class CS extends Thread {
    private ServerSocket _serverSocket;
    private String _ip = "0";

    public static int _port = 44405;

    public static void main(String[] args) throws Exception {


        CS server = new CS();

        System.out.println("Connect Server listen on port " + _port);
        server.start();
    }

    public void run() {

        System.out.println("Connect Server listen on port " + _port);
        while (true) {
            try {

                System.out.println("CS used mem:" + getUsedMemoryMB() + "MB");
                Socket connection = _serverSocket.accept();
                ConnectTheard c = new ConnectTheard(connection);


            } catch (IOException e) {
            }
        }
    }

    public long getUsedMemoryMB() {
        return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime()
                .freeMemory()) / 1024 / 1024;
    }

    public CS() throws Exception {
        super("AppMain");

        System.out.println("CS used mem:" + getUsedMemoryMB() + "MB");

        String hostname = "*";

        if (!"*".equals(hostname)) {
            InetAddress adr = InetAddress.getByName(hostname);
            _ip = adr.getHostAddress();
            _serverSocket = new ServerSocket(_port, 50, adr);
        } else {
            _serverSocket = new ServerSocket(_port);
        }

    }
}
